package com.design.composite.org;

import java.util.ArrayList;
import java.util.List;

// 公司类，实现了组件接口
class Company implements Component {
    private String name;
    private List<Component> departments = new ArrayList<>();

    public Company(String name) {
        this.name = name;
    }

    public void addDepartment(Component department) {
        departments.add(department);
    }

    @Override
    public void display() {
        System.out.println("Company: " + name);
        for (Component department : departments) {
            department.display();
        }
    }

    @Override
    public double getSalary() {
        double totalSalary = 0;
        for (Component department : departments) {
            totalSalary += department.getSalary();
        }
        return totalSalary;
    }
}

